package pl.elka.simulator.core.configurationCommand.impl.param;

import java.util.ArrayList;
import java.util.List;

import pl.elka.simulator.core.IPaintable;
import pl.elka.simulator.core.Position;
import pl.elka.simulator.core.configurationCommand.ICommandParam;
import pl.elka.simulator.core.configurationCommand.ICommandParamConstructor;
import pl.elka.simulator.mediator.ConstraintParts;

public class PositionChainParamConstructor implements ICommandParamConstructor{

	private boolean constructed = false;
	private List<Position> positions = new ArrayList<Position>();//wierzcholki ograniczenia
	@Override
	public ICommandParamConstructor newInstance() {		
		return new PositionChainParamConstructor();
	}

	@Override
	public void appendPart(String partName, Object value) {
		if(ICommandParamConstructor.POSITION.equals(partName)){
			Position position = (Position)value;
			for(Position p:positions){
				if(position.near(p,0.02f)){
					constructed = true;
					return;
				}				
			}
			//jesli nie instnieje bliska pozycja, to dodajemy
			positions.add(position);
		}
		
	}

	@Override
	public boolean isParamConstruced() {
		return constructed;
	}

	@Override
	public ICommandParam getParam() {
		PositionsListCommandParam p = new PositionsListCommandParam();
		p.setPositions(positions);
		return p;
	}
	public IPaintable getVisibleParts(){
		return new ConstraintParts(positions);
	}

}
